﻿// -----------------------------------------------------------------------
// <copyright file="StringCalcFunctions.cs" company="">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace A14_EX01_4
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class StringCalcFunctions
    {
        public static bool IsBinary(string i_recievedString)
        {
            bool returnedValue = true;
            int i = 0;
            while (i_recievedString.Length > i)
            {
                if (i_recievedString[i] == '0' || i_recievedString[i] == '1')
                {
                    i++;
                }
                else
                {
                    returnedValue = false;
                    i = i_recievedString.Length;
                }
            }

            return returnedValue;
        }

        public static bool Have5Chars(string i_recievedString)
        {
            bool returnedValue = false;
            if (i_recievedString.Length == 5)
            {
                returnedValue = true;
            }

            return returnedValue;
        }

        public static int Convert5BinaryCharsStringToInt(string i_fiveBinaryCharsString)
        {
            int intConversion;
            int decimalNumber = 0;
            int j = 1;
            int remainder;
            bool isValid = int.TryParse(i_fiveBinaryCharsString, out intConversion);
            if (isValid)
            {
                while (intConversion != 0)
                {
                    remainder = intConversion % 10;
                    decimalNumber = decimalNumber + (remainder * j);
                    j = j * 2;
                    intConversion = intConversion / 10;
                }
            }

            return decimalNumber;
        }

        public static bool Is5DigitsNumberIsPrime(int i_fiveDigitsNumber)
        {
            bool returnedValue = true;
            if (i_fiveDigitsNumber == 2 || i_fiveDigitsNumber == 1)
            {
                returnedValue = false;
            }

            for (int i = 2; i < (int)Math.Sqrt(i_fiveDigitsNumber); i++)
            {
                if (i_fiveDigitsNumber % i == 0)
                {
                    returnedValue = false;
                }
            }

            return returnedValue;
        }
    }
}
